package org.zoomdev.zoom.common.xml;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.zoomdev.zoom.common.exceptions.ZoomException;

import java.io.IOException;
import java.io.InputStream;

public class XML {

    protected static XmlMapper mapper = new XmlMapper();

    static {
        mapper.configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true);
    }


    public static <T> T parse(String content, Class<T> classOfT) {
        try {
            return mapper.readValue(content, classOfT);
        } catch (JsonProcessingException e) {
            throw new ZoomException(e);
        }
    }


    public static <T> T parse(InputStream content, Class<T> classOfT) {
        try {
            return mapper.readValue(content, classOfT);
        } catch (JsonProcessingException e) {
            throw new ZoomException(e);
        } catch (IOException e) {
            throw new ZoomException(e);
        }
    }
}
